package com.atguigu.gmall.order.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.UserAuthUtil;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.order.vo.OrderConfirmRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/inner/rpc/order")
public class OrderRpcController {

    @Autowired
    OrderBizService orderBizService;
    @Autowired
    OrderInfoService orderInfoService;

    //获取订单确认数据
    @GetMapping("/confirmdata")
    public Result<OrderConfirmRespVo> orderConfirmData (){
        OrderConfirmRespVo orderConfirmRespVo= orderBizService.orderConfirmData();
        return Result.ok(orderConfirmRespVo);
    }

    //根据 orderId,userId 查询订单数据 orderInfo
    @GetMapping("/info/{id}")
    public Result<OrderInfo> getOrderInfoById(@PathVariable("id") Long id){
        Long userId = UserAuthUtil.getUserId();
        OrderInfo orderInfo = orderInfoService.getOrderInfoByIdAndUserId(id,userId);
        return Result.ok(orderInfo);
    }

    //保存秒杀单
    @PostMapping("/seckill/order")
    public Result<Long> saveSeckillOrder(@RequestBody OrderInfo orderInfo){
        Long orderId = orderBizService.saveSeckillOrder(orderInfo);
        return Result.ok(orderId);
    }
}
